﻿@model Ymca.Web.Models.Blog.SearchViewModel

<h2>Search</h2>

@if (Roles.IsUserInRole(User.Identity.Name, "Admin"))
{
	using (Html.BeginForm("Search", "Blog", FormMethod.Get, new { @class = "form-inline", role = "form" }))
	{
		<a class="btn btn-primary" href="@Url.Action("Create", "Blog", new { backPage = ViewBag.BackPage })">Add</a>	
		<div class="form-group">
			@Html.TextBoxFor(model => model.Search, null, new { @class = "form-control", placeholder = "Search" })
		</div>
		<div class="form-group">
			<button type="submit" class="btn btn-primary" type="submit">Search</button>
		</div>
	}
}

@if (Model.Posts != null && Model.Posts.Count() > 0)
{
	<ul>
		@foreach (var post in Model.Posts)
		{
			<li>
				<div>
					@string.Format("{0} : {1}", post.Date.ToShortDateString(), post.Title)
				</div>
				<div>
					@(new HtmlString(post.Body))
				</div>
				@if (Roles.IsUserInRole(User.Identity.Name, "Admin"))
				{
					<div>
						<a class="btn" href="@Url.Action("Edit", "Blog", new { id = post.Id, backPage = ViewBag.BackPage })"><i class="icon-pencil"></i>Edit</a>
						<a class="btn" href="@Url.Action("Delete", "Blog", new { id = post.Id, backPage = ViewBag.BackPage })"><i class="icon-trash"></i>Delete</a>
					</div>
				}
			</li>
		}
	</ul>
	@Html.PagedListPager(Model.Posts, page => Url.Action("Index", new { page = page, search = Model.Search }))
}
else
{
	<span>There is no atems to show.</span>
}